home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / MacApp Release 10 / MacApp Release 10 - HD Ready / Libraries / Framework / Includes / UControl.h < prev    next >
Encoding:
Text File  |  1996-04-03  |  21.2 KB  |  631 lines  |  [TEXT/MPS ]

  1. // UControl.h
  2. // Copyright © 1984-96 by Apple Computer, Inc. All rights reserved.
  3.  
  4. #ifndef __UCONTROL__
  5. #define __UCONTROL__
  6.  
  7. // MacApp
  8.  
  9. // Included for gSystemStyle
  10. #ifndef __UMACAPPGLOBALS__
  11. #include "UMacAppGlobals.h"
  12. #endif
  13.  
  14. #ifndef __UTRACKER__
  15. #include "UTracker.h"
  16. #endif
  17.  
  18. #ifndef __UVIEW__
  19. #include "UView.h"
  20. #endif
  21.  
  22. // Toolbox
  23.  
  24. #ifndef __CONTROLS__
  25. #include <Controls.h>
  26. #endif
  27.  
  28. //----------------------------------------------------------------------------------------
  29. // Forward and external class declarations. 
  30. //----------------------------------------------------------------------------------------
  31.  
  32. class TScroller;
  33. class TToolboxEvent;
  34. class TList;
  35.  
  36. //----------------------------------------------------------------------------------------
  37. // TControl: An abstract class that represents a control.
  38. //----------------------------------------------------------------------------------------
  39.  
  40. class TControl : public TView
  41. {
  42.     MA_DECLARE_CLASS;
  43.     
  44. public:
  45.     //------------------------------------------------------------------------------------
  46.     // Initialize and Free
  47.     //------------------------------------------------------------------------------------
  48.  
  49.     TControl();
  50.         // Constructor
  51.     virtual ~TControl();
  52.         // Destructor
  53.         
  54.     void IControl(TView* itsSuperView,
  55.                                  const VPoint& itsLocation,
  56.                                  const VPoint& itsSize,
  57.                                  SizeDeterminer itsHSizeDet,
  58.                                  SizeDeterminer itsVSizeDet,
  59.                                  const TextStyle& itsTextStyle = gSystemStyle);// control's text style
  60.         //  Initialize a control procedurally.
  61.  
  62.     //------------------------------------------------------------------------------------
  63.     // Standard signature support.
  64.     //------------------------------------------------------------------------------------
  65.  
  66.     virtual IDType GetStandardSignature();    // override 
  67.         // Returns this class's standard signature.
  68.  
  69.     //------------------------------------------------------------------------------------
  70.     // Stream I/O protocol support.
  71.     //------------------------------------------------------------------------------------
  72.  
  73.     virtual void ReadFields(TStream* aStream);    // override 
  74.     
  75.     virtual void WriteFields(TStream* aStream);    // override 
  76.  
  77.     //------------------------------------------------------------------------------------
  78.     // View method overrides
  79.     //------------------------------------------------------------------------------------
  80.  
  81.     virtual void ComputeFrame(VRect& newFrame);
  82.         // Called to compute the control's size.
  83.  
  84.     virtual Boolean ContainsMouse(const VPoint& theMouse);
  85.         // Returns true if 'theMouse is currently in the controls area.
  86.  
  87.     virtual void ControlArea(VRect& theArea);
  88.         // Returns in 'theArea' the controls active area.
  89.  
  90.     virtual CRect ControlQDArea();
  91.         // Returns in 'theArea' the controls active area (in QD coordinates).
  92.  
  93.     virtual void Dim();
  94.         // dims the current image in the TControl
  95.  
  96.     virtual void DimState(Boolean state, Boolean redraw);
  97.         // If we are not currently dimmed then set fDimmed to 'state.and if 'redraw' is
  98.         // true then call DrawContents.
  99.  
  100.     virtual void DoMouseCommand(VPoint& theMouse, TToolboxEvent* event,
  101.                                        CPoint hysteresis);
  102.         // Creates a control tracker command, which is posted.
  103.  
  104.     virtual void DoEvent(EventNumber eventNumber,
  105.                                 TEventHandler* source,
  106.                                 TEvent* event);
  107.         // Handles the mTurnOn, mTurnOff and mToggle messages by adjusting highlighting
  108.         
  109.     virtual Boolean Focus();
  110.         // Calls Inherited::Focus and if its true then sets the port's text style and
  111.         // returns true, if it can't be focused returns false.
  112.  
  113.     virtual void Flash();
  114.         // Causes a control to flash with an 8 tick delay.
  115.  
  116.     virtual void Hilite();
  117.         // hilites the current image in the TControl
  118.  
  119.     virtual void HiliteState(Boolean state, Boolean redraw);
  120.         // If our fHilite is not 'state' the set it to 'state' before calling Hilite.
  121.         // Note: hilite is only called if 'redraw is true and we can Focus.
  122.  
  123.     virtual void Inset(const VPoint& delta, Boolean redraw);
  124.         // If we are sizable then offset fInset to 'dh' & 'dv' redrawing if 'redraw' is
  125.         // true.
  126.  
  127.     virtual Boolean IsDimmed();
  128.         // Returns true if the control is currently dimmed.
  129.  
  130.     virtual void GetAdornExtent(VRect& itsAdornExtent);
  131.         // Returns the adorn extent for adorning this view
  132.  
  133.     virtual EventNumber GetEventNumber(); // Override
  134.         // Returns fEventNumber
  135.  
  136.     virtual void SetAdornment(/*CntlAdornment*/ short newAdornment,
  137.                                      Boolean redraw);
  138.         // Set fAdornment of the 2.0-compatibility adorner.
  139.  
  140.     virtual void GetAdornment(CntlAdornment& itsAdornment);
  141.         // Return fAdornment of the 2.0-compatibility adorner.
  142.  
  143.     virtual void SetPenSize(CPoint newPenSize);
  144.     virtual void GetPenSize(CPoint& itsPenSize);
  145.         // For 2.0-compatible adornment.
  146.  
  147.     virtual void SetInset(const VRect& newInset, Boolean redraw);
  148.         // Set fInset to 'newInset' redrawing if 'redraw' is true.
  149.  
  150.     virtual void InstallColor(const CRGBColor& theColor, Boolean redraw);
  151.         // Sets the color field of our text style record to 'theColor', if 'redraw' then
  152.         // call DrawContents.
  153.  
  154.     virtual void InstallTextStyle(const TextStyle& theTextStyle, Boolean redraw);
  155.         // Sets fTextStyle to 'theTextStyle', if 'redraw' then call DrawContents.
  156.  
  157.     virtual void SetFrame(const VRect& newFrame, Boolean invalidate);
  158.         // Calls Inherited::SetFrame before calling ForceRedraw.
  159.  
  160.     virtual void TrackFeedback(TrackPhase aTrackPhase,
  161.                                         const VPoint& anchorPoint,
  162.                                         const VPoint& previousPoint,
  163.                                         const VPoint& nextPoint,
  164.                                         Boolean mouseDidMove,
  165.                                         Boolean turnItOn);
  166.         // Doesn't use the default feedback
  167.  
  168.     virtual void TrackMouse(TrackPhase aTrackPhase,
  169.                                    VPoint& anchorPoint,
  170.                                    VPoint& previousPoint,
  171.                                    VPoint& nextPoint,
  172.                                    Boolean mouseDidMove);
  173.         // Called back from tracking command. Handles tracking of the mouse and then calls
  174.         // DoChoice on TrackRelease.
  175.  
  176. //----------------------------------------------------------------------------------------
  177. // data members
  178. //----------------------------------------------------------------------------------------
  179. public:
  180.  
  181.     VRect fInset;                                // amount to inset the control portion of
  182.                                                 // the view
  183.  
  184.     EventNumber fEventNumber;                    // the event number to automatically pass
  185.                                                 // up the line via HandleEvent
  186.  
  187.     short fTextStyleRsrcID;                        // Rsrc ID of 'TxSt' resource which has
  188.                                                 // TextStyle information.
  189.  
  190.     TextStyle fTextStyle;                        // the TextStyle to use when rendering
  191.                                                 // this view
  192.  
  193.     Boolean fHilite;                            // is this view hilited
  194.  
  195.     Boolean fDimmed;                            // is this view dimmed
  196.  
  197.     Boolean fSizeable;                            // is the control portion of this view
  198.                                                 // sizeable
  199.  
  200.     Boolean fPreferOutline;                        // prefer outline fonts?
  201.  
  202.  
  203. };
  204.  
  205.  
  206. //----------------------------------------------------------------------------------------
  207. // TCtlMgr: An abstract class that represents a toolbox Control Manager control.
  208. //----------------------------------------------------------------------------------------
  209.  
  210. class TCtlMgr : public TControl
  211. {
  212.     MA_DECLARE_CLASS;
  213.     
  214. public:
  215.  
  216.     //------------------------------------------------------------------------------------
  217.     // Initialize and Free
  218.     //------------------------------------------------------------------------------------
  219.  
  220.     TCtlMgr();
  221.         // Constructor
  222.         
  223.     void ICtlMgr(TView* itsSuperView,
  224.                                 const VPoint& itsLocation,
  225.                                 const VPoint& itsSize,
  226.                                 SizeDeterminer itsHSizeDet,
  227.                                 SizeDeterminer itsVSizeDet,
  228.                                 const CStr255& itsTitle,
  229.                                 long itsVal,
  230.                                 long itsMin,
  231.                                 long itsMax,
  232.                                 short itsProcID,
  233.                                 const TextStyle& itsTextStyle = gSystemStyle);// control's text style
  234.         // Initialize procedurally.
  235.  
  236.     virtual ~TCtlMgr();
  237.         // Set the size of control to zero call DisposeControl, then call Inherited::Free.
  238.  
  239.  
  240.     //------------------------------------------------------------------------------------
  241.     // Rest of methods
  242.     //------------------------------------------------------------------------------------
  243.  
  244.     virtual TObject* Clone();
  245.         // Calls Inherited::Clone and then clones owned objects.
  246.  
  247.     virtual void BeInPort(GrafPtr itsPort);
  248.     // Sets the control to be in 'itsPort', by setting the contrlOwner field of the
  249.     // ControlRef.
  250.  
  251.     virtual void CreateCMgrControl(const CStr255& itsTitle,
  252.                                           long itsVal,
  253.                                           long itsMin,
  254.                                           long itsMax,
  255.                                           short itsProcID);
  256.         // Used to create a new control, calls NewControl to create the control.
  257.  
  258.     virtual void InstallColor(const CRGBColor& theColor, Boolean redraw);
  259.         // Calls Inherited and sets the control color table.
  260.  
  261.     virtual void DimState(Boolean state, Boolean redraw);
  262.         // Set the dim state to 'state' and redrawing it if 'redraw'.
  263.  
  264.     virtual void DoMouseCommand(VPoint& theMouse,
  265.                                        TToolboxEvent* event,
  266.                                        CPoint hysteresis);
  267.         // Handles mouse downs in the control by calling TestControl and DoChoice
  268.  
  269.     virtual void Draw(const VRect& area);
  270.         // Draws the control by calling the toolbox routine ShowControl.
  271.  
  272.     virtual PicHandle AsPictForPrinting();
  273.  
  274.     virtual VCoordinate GetLongMax();
  275.         // Returns the current fLongMax value.
  276.  
  277.     virtual VCoordinate GetLongMin();
  278.         // Returns the current fLongMin value.
  279.  
  280.     virtual VCoordinate GetLongVal();
  281.         // Returns the current fLongVal value.
  282.  
  283.     virtual void SetLongMax(VCoordinate itsMax,
  284.                                    Boolean redraw);
  285.         // Sets fLongMax to 'itsMax', redrawing if required.
  286.  
  287.     virtual void SetLongMin(VCoordinate itsMin, Boolean redraw);
  288.         // Sets flongMin to 'itsMin', redrawing if required.
  289.  
  290.     virtual void SetLongVal(VCoordinate itsVal, Boolean redraw);
  291.         // Sets fLongVal to 'itsVal' redrawing if required.
  292.  
  293.     virtual void SetLongValues(VCoordinate itsVal,
  294.                                       VCoordinate itsMin,
  295.                                       VCoordinate itsMax,
  296.                                       Boolean redraw);
  297.         // Sets all of the values at once, redrawing if required.
  298.  
  299.     virtual short GetHelpState();
  300.         // Override to support help states for controls
  301.     
  302.     //------------------------------------------------------------------------------------
  303.     // Methods to manipulate the Control Manager control values
  304.     //------------------------------------------------------------------------------------
  305.     
  306.     virtual short GetMax();
  307.         // Returns the maximum value of the Control Manager control.
  308.  
  309.     virtual short GetMin();
  310.         // Returns the minimum value of the Control Manager control.
  311.  
  312.     virtual void GetText(CStr255& theText);
  313.         // Returns the controls title, if any.
  314.  
  315.     virtual short GetVal();
  316.         // Returns the current value of the Control Manager control.
  317.  
  318.     virtual short GetVariant();
  319.         // Returns the variant control value for the Control Manager control.
  320.  
  321.     virtual void SetMax(short itsMax, Boolean redraw);
  322.         // While focused sets the maximum value of the Control Manager control to 'itsMax'.
  323.  
  324.     virtual void SetMin(short itsMin, Boolean redraw);
  325.         // While focused sets the minimum value of the Control Manager control to 'itsMin'.
  326.  
  327.     virtual void SetText(const CStr255& itsText, Boolean redraw);
  328.         // Sets the controls title to 'itsText', redrawing if required.
  329.  
  330.     virtual void SetVal(short newVal, Boolean redraw);
  331.         // While focused sets the Control Manager controls value to 'newVal', redrawing if
  332.         // required.
  333.  
  334.     virtual void SetValues(short itsVal,
  335.                                   short itsMin,
  336.                                   short itsMax,
  337.                                   Boolean redraw);
  338.         // While focused sets all the values of the Control Manager control, at once,
  339.         // redrawing if required.
  340.  
  341.     virtual void HiliteState(Boolean state, Boolean redraw);
  342.         // Set the hilite state to 'state', redrawing if required.If hilite state is
  343.         // currently 'state' then does nothing.
  344.  
  345.     virtual void Inset(const VPoint& delta, Boolean redraw);
  346.         // If we are sizable then offset fInset to 'dh' & 'dv' redrawing if 'redraw' is
  347.         // true.
  348.  
  349.     virtual void SetInset(const VRect& newInset, Boolean redraw);
  350.         // Set fInset to 'newInset' redrawing if 'redraw' is true.
  351.  
  352.     virtual void AdjustCtlMgrControl(Boolean redraw);
  353.         // Adjusts ctl mgr control taking into account control area.
  354.  
  355.     virtual Boolean IsCMgrVisible();
  356.         // Returns true if the control is currently visible, false if not.
  357.  
  358.     virtual void SetFrame(const VRect& newFrame, Boolean invalidate);
  359.         // If the control is resizable calls the toolbox routines MoveControl &
  360.         // SizeControl before calling Inherited::SetFrame.
  361.  
  362.     virtual void UpdateCoordinates();// override
  363.         // Keeps the control manager control in synch with any VSpace or QDSpace
  364.         // origin changes.
  365.  
  366.     virtual Boolean SetCMgrVisibility(Boolean beVisible);
  367.         // Sets the visibility of the control to 'isVisible'.
  368.         // Returns old state
  369.  
  370.     virtual void Show(Boolean state, Boolean redraw);
  371.         // Keep the CMgr visibility state synchronized.
  372.  
  373. //----------------------------------------------------------------------------------------
  374. // data members
  375. //----------------------------------------------------------------------------------------
  376. public:
  377.  
  378.     VCoordinate fLongVal;                        // the current value
  379.  
  380.     VCoordinate fLongMin;                        // the minimum setting
  381.  
  382.     VCoordinate fLongMax;                        // the maximum setting
  383.  
  384.     ControlRef fCMgrControl;                    // the Control Manager Control that is
  385.                                                 // being managed
  386.  
  387.     short    fProcID;                            // Save the procID for use when cloning
  388.  
  389.     short fBitsToShift;                            // # bits shifted to convert between short
  390.                                                 // and long value.
  391.  
  392. };
  393.  
  394.  
  395. //----------------------------------------------------------------------------------------
  396. // TScrollBar: A subclass of TCtlMgr that maps between longint values for our view
  397. // coordinates and the integers of a toolbox scrollbar.
  398. //----------------------------------------------------------------------------------------
  399.  
  400. class TScrollBar : public TCtlMgr
  401. {
  402.     MA_DECLARE_CLASS;
  403.     
  404. public:
  405.  
  406.     //------------------------------------------------------------------------------------
  407.     // Initialize and Free
  408.     //------------------------------------------------------------------------------------
  409.  
  410.     TScrollBar();
  411.         // Constructor
  412.     virtual ~TScrollBar();
  413.         // Destructor
  414.         
  415.     void IScrollBar(TView* itsSuperView,
  416.                                    const VPoint& itsLocation,
  417.                                    const VPoint& itsSize,
  418.                                    SizeDeterminer itsHSizeDet,
  419.                                    SizeDeterminer itsVSizeDet,
  420.                                    VHSelect itsDirection,
  421.                                    long itsVal,
  422.                                    long itsMin,
  423.                                    long itsMax);
  424.         // Initialize a scrollbar procedurally.
  425.  
  426.     //------------------------------------------------------------------------------------
  427.     // Standard signature support.
  428.     //------------------------------------------------------------------------------------
  429.  
  430.     virtual IDType GetStandardSignature();    // override 
  431.         // Returns this class's standard signature.
  432.  
  433.     //------------------------------------------------------------------------------------
  434.     // Stream I/O protocol support.
  435.     //------------------------------------------------------------------------------------
  436.  
  437.     virtual void ReadFields(TStream* aStream);    // override 
  438.     
  439.     virtual void WriteFields(TStream* aStream);    // override 
  440.  
  441.     //------------------------------------------------------------------------------------
  442.     // View method overrides
  443.     //------------------------------------------------------------------------------------
  444.     virtual void DeltaValue(VCoordinate delta);
  445.         // Does range checking on 'delta' checking it against fLongMin & fLongMax for the
  446.         // scrollbar.
  447.  
  448.     virtual void DoMouseCommand(VPoint& theMouse,
  449.                                        TToolboxEvent* event,
  450.                                        CPoint hysteresis);
  451.         // Handles the mouse down in the various parts of the scrollbar.
  452.  
  453.     virtual void TrackScrollBar(short partCode);
  454.         // Tracks the scrollbar by calling DeltaValue.
  455.  
  456.     virtual void ActionProc(short partCode);
  457.         // Forwarded to from the global routine: ActionProcForTScrollBar which was set as
  458.         // the ScrollBar's action proc. Typically forwards again to TrackScrollBar after
  459.         // bounds checking and Updates before returning to the ScrollBar.
  460.  
  461.     //------------------------------------------------------------------------------------
  462.     // data members
  463.     //------------------------------------------------------------------------------------
  464. public:
  465.  
  466.     VHSelect fDirection;                        // is this a horizontal or vertical
  467.                                                 // scrollbar
  468.  
  469. };
  470.  
  471. //----------------------------------------------------------------------------------------
  472. // TScrollerScrollBar: A subclass of TScrollBar that is associated with one or more
  473. // scrollers.
  474. //----------------------------------------------------------------------------------------
  475.  
  476. class TScrollerScrollBar : public TScrollBar
  477. {
  478.     MA_DECLARE_CLASS;
  479.     
  480. public:    
  481.  
  482.     //------------------------------------------------------------------------------------
  483.     // Initialize and Free
  484.     //------------------------------------------------------------------------------------
  485.  
  486.     TScrollerScrollBar();
  487.         // Constructor
  488.         
  489.     void IScrollerScrollBar(TView* itsSuperView,
  490.                                     const VPoint& itsLocation,
  491.                                     const VPoint& itsSize,
  492.                                     SizeDeterminer itsHSizeDet,
  493.                                     SizeDeterminer itsVSizeDet,
  494.                                     VHSelect itsDirection,
  495.                                     long itsMax,
  496.                                     TScroller* itsScroller);
  497.         // Initialize the scrollbar procedurally.
  498.  
  499.     virtual ~TScrollerScrollBar();
  500.         // If the scrollers are not NULL then first detach the scrollbars from them before
  501.         // freeing the scrollers, then call Inherited::Free.
  502.  
  503.  
  504.     //------------------------------------------------------------------------------------
  505.     // Methods
  506.     //------------------------------------------------------------------------------------
  507.  
  508.     virtual TObject* Clone();
  509.         // Calls Inherited::Clone and then clones owned objects.
  510.  
  511.     //------------------------------------------------------------------------------------
  512.     // Standard signature support.
  513.     //------------------------------------------------------------------------------------
  514.  
  515.     virtual IDType GetStandardSignature();    // override 
  516.         // Returns this class's standard signature.
  517.  
  518.     //------------------------------------------------------------------------------------
  519.     // Stream I/O protocol support.
  520.     //------------------------------------------------------------------------------------
  521.  
  522.     virtual void ReadFields(TStream* aStream);    // override 
  523.     
  524.     virtual void WriteFields(TStream* aStream);    // override 
  525.  
  526.     //------------------------------------------------------------------------------------
  527.     // Methods
  528.     //------------------------------------------------------------------------------------
  529.  
  530.     virtual void AttachScroller(TScroller* itsScroller);
  531.         // IF 'itsScroller' is not NULL then add it to our list and attach ourselves to it.
  532.  
  533.     virtual void BeInPort(GrafPtr itsPort);
  534.         // Call Inherited::BeInPort and then set our visibility based on the state of the
  535.         // window we are in.
  536.  
  537.     virtual void Activate(Boolean entering);
  538.         // If 'entering' is true then show ourselves, otherwise just call Draw to frame
  539.         // our area.
  540.  
  541.     virtual void DoMouseCommand(VPoint& theMouse,
  542.                                        TToolboxEvent* event,
  543.                                        CPoint hysteresis);
  544.         // Handles mouse downs in the scrollbar.
  545.  
  546.     virtual void Draw(const VRect& area);
  547.         // Draws a frame around the controls area before calling Inherited::Draw.
  548.  
  549.     virtual void TrackScrollBar(short partCode);
  550.         // Called to handle tracking of the scrollbar by calling DeltaValue.
  551.  
  552.     //------------------------------------------------------------------------------------
  553.     // data members
  554.     //------------------------------------------------------------------------------------
  555. public:
  556.  
  557.     TList* fScrollers;                            // the associated scrollers if any
  558.  
  559. };
  560.  
  561.  
  562. //----------------------------------------------------------------------------------------
  563. // TControlTracker: A Tracker adapted for tracking controls.
  564. //----------------------------------------------------------------------------------------
  565.  
  566. class TControlTracker : public TTracker
  567. {
  568.     MA_DECLARE_CLASS;
  569.     
  570. public:
  571.  
  572.     //------------------------------------------------------------------------------------
  573.     // Initialize and Free
  574.     //------------------------------------------------------------------------------------
  575.  
  576.     TControlTracker();
  577.         // Constructor
  578.     virtual ~TControlTracker();
  579.         // Destructor
  580.         
  581.     void IControlTracker(TControl* theControl, const VPoint& itsMouse);
  582.         // Initialize the tracker procedurally.
  583.  
  584.     //------------------------------------------------------------------------------------
  585.     // data members
  586.     //------------------------------------------------------------------------------------
  587. public:
  588.  
  589.     TControl* fControl;    // the control being tracked
  590.  
  591. };
  592.  
  593. //------------------------------------------------------------------------------------
  594. // Utility class.
  595. //------------------------------------------------------------------------------------
  596.  
  597. class CWhileFocused
  598. {
  599. protected:
  600.     void* operator new(size_t size);            // prohibit "new CWhileFocused"
  601.     void operator delete(void* obj);            // avoid compiler warnings
  602.     
  603.  
  604. public:
  605.     // Constructor
  606.     CWhileFocused(TCtlMgr* itsCtlMgr,
  607.                   Boolean redraw);
  608.  
  609.     ~CWhileFocused();
  610.     // Restores the focus, removes the failure handler.
  611.  
  612.     void Cleanup();
  613.     
  614.     static void CallCleanup(void* context);
  615.  
  616.     //------------------------------------------------------------------------------------
  617.     // data members
  618.     //------------------------------------------------------------------------------------
  619. protected:
  620.     TCtlMgr* fCtlMgr;
  621.     CPoint fOldControlLocation;
  622.     FailInfo    fFailInfo;                        // the failure record that references
  623.                                                 // the failure handling method
  624.     Boolean fRedraw;
  625.     Boolean fWasVisible;
  626.     Boolean fDidFocus;
  627. };
  628.  
  629. #endif
  630.  
  631.